package cn.netjava.softkid.chapter08;
/*
time for LinkedList = 62
time for ArrayList = 7488
*/
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class ListDemoMid {
  static final int SIZE = 100000;

  static long timeList(List list) {
    long start = System.currentTimeMillis();
    Object obj = new Object();
    for (int i = 0; i < SIZE; i++) {
      // add object to the head of the list
      list.add(i/2, obj);
    }

    return System.currentTimeMillis() - start;
  }

  public static void main(String args[]) {
    // do timing for LinkedList
    System.out.println("time for LinkedList = " + timeList(new LinkedList()));

    // do timing for ArrayList
    System.out.println("time for ArrayList = " + timeList(new ArrayList()));
  }
}
